#include<iostream>
#include<list>
#include<stack>
using namespace std;

template <class T>
class SetOfStacks
{
public:
	int limit;
	list< stack<T > > buffer;
public:
	SetOfStacks(int n=7){
		limit=n;
	}
	
	const T& pop(){
		const T& item=buffer.back().top();
		buffer.back().pop();
		int s=buffer.size();
		cout<<s<<endl;	
		if(buffer.back().size()==0)
			buffer.pop_back();
		s=buffer.size();
		cout<<s<<endl;		
		return item;
	}
	void push(const T& item);
	T& peek(){
		return buffer.back().top();
	}
//	bool isEmpty(); 
};

template <class T>
void SetOfStacks<T>::push(const T& item)
{
	if(buffer.back().size()>=limit){
		buffer.push_back(stack< T >());
	}
	buffer.back().push(item);
}

class test
{
public:
	int a;
	int b;
	test(int a,int b){
		this->a=a;
		this->b=b;
	}
}; 


int main()
{

	stack<test> stk;
	test t1(1,3);
	stk.push(t1);
	test* t3=new test(5,8);
	test &t2=stk.top();
	t1=*t3;
	SetOfStacks<int> ss(1);
	int aa=8;
	int bb=9;
	int &cc=bb;
	int &dd=aa;
	ss.push(dd);
	ss.push(cc);
	int a=ss.pop();
	int b=ss.pop();
	cout<<a<<b<<endl;
	return 0;
}
